//
// Created by jack on 2021/2/2.
//

#include "weilapb_defines.h"

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "weilapb.h"
#include "weilapb_error.h"
#include "weilapb_internal.h"

PBErrorInfo gErrorInfo;

void weilapb_error(PB_INT32 errCode, const char* pFormat, ...) {
    va_list valist;

    if (strlen(pFormat) > 240) {
        return;
    }

    memset(gErrorInfo.errMsg, 0, 256);
    va_start(valist, pFormat);
    vsprintf(gErrorInfo.errMsg, pFormat, valist);
    va_end(valist);
    gErrorInfo.errCode = errCode;

    WL_LOG("!!!!Error Happen:code:%d msg:%s\n", errCode, gErrorInfo.errMsg);
}

PBErrorInfo weilapb_getErrorInfo() {
    PBErrorInfo info;
    memcpy(&info, &gErrorInfo, sizeof(info));
    return info;
}
